package atmGUI;


import util.Util;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

//ATM_GUI_Main
public class ATM_GUI_Main extends JFrame {
    public static final String FILE_PATH = "user.dat";
    private List<User> usersList = new ArrayList();
    private Image bgdImage = Util.getImage("/image/background.jpg");  //背景图
    private User loginUser;//登陆用户实例
    private LoginPanel loginPanel = new LoginPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private QueryPanel queryPanel = new QueryPanel(this);
    private WithdrawalPanel withdrawalPanel = new WithdrawalPanel(this);
    private SavePanel savePanel = new SavePanel(this);
    private TransferPanel transferPanel = new TransferPanel(this);
    private ChangePwdPanel changePwdPanel = new ChangePwdPanel(this);
    private CardLayout cardLayout = new CardLayout();

    public ATM_GUI_Main() {
        init();//初始化用户集合
        //设置背景图
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgdImage, 0, 0, 1024, 768, this);
            }
        });

        //设置卡牌布局
        setLayout(cardLayout);
        //添加卡牌
        this.add("login", loginPanel);
        this.add("menu", menuPanel);
        this.add("query", queryPanel);
        this.add("withdrawal", withdrawalPanel);
        this.add("save", savePanel);
        this.add("transfer", transferPanel);
        this.add("changePwd", changePwdPanel);
        //设置窗口大小
        this.setSize(1024, 768);
        //设置title
        this.setTitle("中国银行");
        //设置窗口点击关闭程序结束
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //设置窗口可见
        this.setVisible(true);

    }

    //初始化用户集合
    public void init() {
        usersList.add(new User("aaa", "111", 1000));
        usersList.add(new User("bbb", "222", 2000));
        usersList.add(new User("ccc", "333", 3000));
        usersList.add(new User("ddd", "444", 2500));
        usersList.add(new User("eee", "555", 1500));
    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

    //Main
    public static void main(String[] args) {
        ATM_GUI_Main atm_gui_main = new ATM_GUI_Main();
    }

    public List<User> getUsersList() {
        return usersList;
    }

    public void setUsersList(List<User> usersList) {
        this.usersList = usersList;
    }

    public User getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(User loginUser) {
        this.loginUser = loginUser;
    }

    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public void setLoginPanel(LoginPanel loginPanel) {
        this.loginPanel = loginPanel;
    }

    public MenuPanel getMenuPanel() {
        return menuPanel;
    }

    public QueryPanel getQueryPanel() {
        return queryPanel;
    }

    public SavePanel getSavePanel() {
        return savePanel;
    }

    public WithdrawalPanel getWithdrawalPanel() {
        return withdrawalPanel;
    }

    public CardLayout getCardLayout() {
        return cardLayout;
    }
}
